package ferramentas;

import java.awt.event.ItemEvent;

import javax.swing.JComboBox;

public class ItemData 
{
    private String description;
    private int key;
    private int index;
    
    public ItemData() 
    {

    }
    
    public ItemData(int id, String descricao) 
    {
        key = id;
        description = descricao;
    }
    
    public ItemData(int indice ,int id, String descricao) 
    {
        key = id;
        index = indice;
        description = descricao;
    }
    
    @Override
    public String toString() 
    {
        return description;
    }
 
    public int getKey() 
    {
        return key;
    }
    
    public int getIndex() 
    {
        return index;
    }
    
    public int getIndexCombo(JComboBox comboBox, int id)
    {
		int indice = -1;
		int dado = -1;
		Object obj;
		for(int i = 0; i < comboBox.getItemCount();i++)
		{
			obj = comboBox.getItemAt(i);
			dado = Integer.parseInt(String.valueOf(((ItemData) obj).getKey()));
            if(id == dado)
            {
            	indice = i;
            }    
		}	
    	return indice;
    }
    
    public int getIdItemData( JComboBox combo )
    {
        Object obj = combo.getSelectedItem();
        return Integer.parseInt(String.valueOf(((ItemData) obj).getKey())) ;     
    }
}

